<link rel="stylesheet" type="text/css" href="${path}/skin/css/jquery.datetimepicker.css"/ >
<script src="${path}/skin/lib/jquery/jquery.datetimepicker.min.js"></script>
<script src="${path}/skin/build/jquery.datetimepicker.full.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$.datetimepicker.setLocale('ch');//设置中文
	$('#datetimepicker_format').datetimepicker({value: new Date(), format: $("#datetimepicker_format_value").val()});

	$("#addBut").on("click",function(){
		var rePassword = $("input[name='rePassword']").val();
		
		var userName = $("input[name='name']").val();
		var password = $("input[name='password']").val();
		var sex = $('input:radio[name="sex"]:checked').val();
		var status = $('input:radio[name="status"]:checked').val();
		var realName = $("input[name='realName']").val();
		var phone = $("input[name='phone']").val();
		var companyId = $("#companyId").find("option:selected").val();
		var level = $("input[name='level']").val();
		var address = $("input[name='address']").val();
		var email = $("input[name='email']").val();
		var joinTime = $("#datetimepicker_format").val();
		var IDcard = $("input[name='IDcard']").val();
		var major = $("input[name='major']").val();
		
		var role = "";
		
		var groupCheckbox=$("input[name='check']");
	    for(i=0;i<groupCheckbox.length;i++){
	        if(groupCheckbox[i].checked){
	        	role =role+ groupCheckbox[i].value+ ',';
	        }
	    }
		
		var flag = true;
		/* if(userName == ""){
			flag = false;
			alert("用户名不能为空！");
		} else if (password == ""){
			flag = false;
			alert("密码不能为空！");
		} else if (rePassword == ""){
			flag = false;
			alert("确认密码不能为空！");
		} else if(!isPhoneNo(phone)){
			flag = false;
			alert("手机号码输入错误！");
		} else if(!isCardNo(IDcard)){
			flag = false;
			alert("身份证号输入错误！");
		} else if(!isEmail(email)){
			flag = false;
			alert("邮箱输入输入错误！");
		} */
		if(flag){
			if(password == rePassword){
				$.post("${path}/user/addUser",{
					userName:userName,
					password:password,
					realName:realName,
					sex:sex,
					status:status,
					phone:phone,
					level:level,
					companyId:companyId,
					address:address,
					email:email,
					joinTime:joinTime,
					IDcard:IDcard,
					major:major,
					
					role:role
				},function(data,status){
					if(data.success){
						window.location.href="${path}/user/list";
					}
				})
			} else {
				alert("两次输入的密码不一致！");
			}
		}
	});
	
	// 验证手机号
	function isPhoneNo(phone) { 
	 var pattern = /^1[34578]\d{9}$/; 
	 return pattern.test(phone); 
	}
	// 验证中文名称
	function isChinaName(name) {
	 var pattern = /^[\u4E00-\u9FA5]{1,6}$/;
	 return pattern.test(name);
	}
	// 验证身份证 
	function isCardNo(card) { 
	 var pattern = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/; 
	 return pattern.test(card); 
	} 
	function isEmail(email) {
		var pattern = /^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/;
		return pattern.test(email);
	}

})
</script>
<div>
	登录名：<input name="name"><br/>
	密码：     <input name="password"><br/>
	确认密码：<input name="rePassword"><br/>
	选择角色：
		#foreach ($role in $map.role)
			<input type="checkbox" name="check" value="${role.ID}" />${role.NAME}
		#end <br/>
	单位名称：
	<select id="companyId" name="">
	     <option value=" " >请选择</option>
	     #foreach ($company in $map.compant)
	        <option value="${company.id}"> ${company.name}</option>
		  #end 
	</select><br/>
	姓名：<input name="realName"><br/>
	性别：<input id="x1" type="radio" value="0" name="sex" checked/>男
		  <input id="x2" type="radio" value="1" name="sex"/>女  <br/>
	电话：<input name="phone"><br/>
	身份证号：<input name="IDcard"><br/>
	级别: <input name="level" value=""><br/>
	专业：<input name="major" value=""><br/>
	住址：<input name="address" value=""><br/>
	邮箱：<input name="email" value=""><br/>
	加入时间: <input type="text" id="datetimepicker_format" class="input input-wide"/><!-- <input name="joinTime" value=""> --><br/>
	状态：<input id="z1" type="radio" value="0" name="status" checked/>正常启用
		 <input id="z2" type="radio" value="1" name="status"/>异常  <br/>
	<button type='button' id="addBut">添加</button>
</div>
